
// 当前准备删除的房屋id
let houseId
console.log(houseId);
Page({
  data: {
    dialogVisible: false,
    // 房屋列表
    houseList: []
  },

  swipeClose(ev) {
    const { instance } = ev.detail
    // 显示 Dialog 对话框
    this.setData({
      dialogVisible: true,
    })

    // swiper-cell 滑块关闭
    instance.close()
    houseId = ev.mark.id

    // if (position === 'right') {

    // }
  },
  async dialogClose(ev) {
    if (ev.detail === 'confirm') {
      const res = await wx.http({
        url: '/room/' + houseId,
        method: 'delete'
      })
      console.log(res);
      this.houseList()
    }
  },
  async onLoad() {
    this.houseList()
  },
  async houseList() {
    const res = await wx.http({
      url: '/room'
    })
    console.log(res);
    this.setData({
      houseList: res.data
    })
  },

  goDetail(ev) {
    wx.navigateTo({
      url: '/house_pkg/pages/detail/index?id=' + ev.mark.id,
    })
  },

  addHouse() {
    wx.navigateTo({
      url: '/house_pkg/pages/locate/index',
    })
  },
})
